
*** Stata version 17.0 was used

********************************************************************************************************************************************************************************************************
*********************************************************************************FIGURE 1**************************************************************************************************************
********************************************************************************************************************************************************************************************************

***GERMANY
cd "C:\Users\Daur\Desktop\APSR submission\Dataverse" //INSERT WORKING DIRECTORY
import excel "Content.xlsx", sheet("Germany") firstrow clear

*generating year variable
gen year=2021 if Date<20220000
replace year=2020 if Date<20210101
replace year=2019 if Date<20200101
replace year=2018 if Date<20190101
replace year=2017 if Date<20180101

*merging the two types of delegitimization
gen type=0
replace type=1 if Statementtype==1 | Statementtype==6

*merging CDU and CSU
gen party=Senderparty
recode party (2=1)

* Collapse Data
collapse (sum) count_type = type (count) total = type, by(party year)

* Calculate Proportion
gen proportion = (count_type / total)*100

* Keep Only Relevant Variables
keep party year proportion

set scheme s2mono

gen prop = string(proportion, "%2.0f") + "%"

***FIGURE 1
scatter proportion year if party == 1, scheme(s1mono) ylabel(0(10)100) ytitle("Share of delegitimizing statements in %") msymbol(S) mlabel(prop) mlabpos(12) mcolor(black) mlabg(2) connect(l) title("Germany: CDU") xtitle("") xscale(range(2016.9 2020.1)) xlabel(,alternate)
graph save germany.gph, replace


***Sweden
import excel "Content.xlsx", sheet("Sweden") firstrow clear

*generating year variable
gen year=2021 if Date<20220000
replace year=2020 if Date<20210101
replace year=2019 if Date<20200101
replace year=2018 if Date<20190101
replace year=2017 if Date<20180101
replace year=2016 if Date<20170101
replace year=2015 if Date<20160101
replace year=2014 if Date<20150101
replace year=2013 if Date<20140101
replace year=2012 if Date<20130101
replace year=2011 if Date<20120101
replace year=2010 if Date<20110101

*generating twoyear variable
gen twoyear=.
replace twoyear=1 if year==2010 | year==2011
replace twoyear=2 if year==2012 | year==2013
replace twoyear=3 if year==2014 | year==2015
replace twoyear=4 if year==2016 | year==2017
replace twoyear=5 if year==2018 | year==2019
replace twoyear=6 if year==2020 | year==2021

*merging the two types of delegitimization
gen type=0
replace type=1 if Statementtype==1 | Statementtype==6

rename Sponsorparty party

* Collapse Data
collapse (sum) count_type = type (count) total = type, by(party twoyear)

* Calculate Proportion
gen proportion = (count_type / total)*100

* Keep Only Relevant Variables
keep party twoyear proportion

set scheme s2mono

gen prop = string(proportion, "%2.0f") + "%"

scatter proportion twoyear if party == 1, scheme(s1mono) ylabel(0(10)100) ytitle("Share of delegitimizing statements in %") msymbol(S) mlabel(prop) mlabpos(1) connect(l) mcolor(gs10) mlabc(gs10) mlabg(2) lcolor(gs10) title("Sweden: M", color(gs10)) xlabel(1 "2010/11" 2 "2012/13" 3 "2014/15" 4 "2016/17" 5 "2018/19" 6 "2020/21", alternate) xtitle("") xscale(range(0.9 6.3))

graph save sweden.gph, replace

graph combine germany.gph sweden.gph, graphregion(color(white))
graph export "Figure1.pdf",replace

********************************************************************************************************************************************************************************************************
*********************************************************************************FIGURE 2**************************************************************************************************************
********************************************************************************************************************************************************************************************************
***GERMANY
import excel "Content.xlsx", sheet("Germany") firstrow clear

*generating year variable
gen year=2021 if Date<20220000
replace year=2020 if Date<20210101
replace year=2019 if Date<20200101
replace year=2018 if Date<20190101
replace year=2017 if Date<20180101

* generating binary variable: legitimizing or not
gen type=0
replace type=1 if Statementtype==2

*merging CDU and CSU
gen party=Senderparty
recode party (2=1)

* Collapse Data
collapse (sum) count_type = type (count) total = type, by(party year)

* Calculate Proportion
gen proportion = (count_type / total)*100

* Keep Only Relevant Variables
keep party year proportion

gen prop = string(proportion, "%2.0f") + "%"

scatter proportion year if party == 1, scheme(s1mono) ylabel(0(10)100) ytitle("Share of legitimizing statements in %") msymbol(S) mlabel(prop) mlabpos(12) mcolor(black) mlabg(2) connect(l) title("Germany: CDU") xtitle("") xscale(range(2016.9 2020.1)) xlabel(,alternate)
graph save germany.gph, replace


***Sweden
import excel "Content.xlsx", sheet("Sweden") firstrow clear

*generating year variable
gen year=2021 if Date<20220000
replace year=2020 if Date<20210101
replace year=2019 if Date<20200101
replace year=2018 if Date<20190101
replace year=2017 if Date<20180101
replace year=2016 if Date<20170101
replace year=2015 if Date<20160101
replace year=2014 if Date<20150101
replace year=2013 if Date<20140101
replace year=2012 if Date<20130101
replace year=2011 if Date<20120101
replace year=2010 if Date<20110101

*generating twoyear variable
gen twoyear=.
replace twoyear=1 if year==2010 | year==2011
replace twoyear=2 if year==2012 | year==2013
replace twoyear=3 if year==2014 | year==2015
replace twoyear=4 if year==2016 | year==2017
replace twoyear=5 if year==2018 | year==2019
replace twoyear=6 if year==2020 | year==2021

* generating binary variable: legitimizing or not
gen type=0
replace type=1 if Statementtype==2
rename Sponsorparty party

* Collapse Data
collapse (sum) count_type = type (count) total = type, by(party twoyear)

* Calculate Proportion
gen proportion = (count_type / total)*100

* Keep Only Relevant Variables
keep party twoyear proportion

gen prop = string(proportion, "%2.0f") + "%"

scatter proportion twoyear if party == 1, scheme(s1mono) ylabel(0(10)100) ytitle("Share of legitimizing statements in %") msymbol(S) mlabel(prop) mlabpos(12) connect(l) mcolor(gs10) mlabc(gs10) mlabg(2) lcolor(gs10) title("Sweden: M", color(gs10)) xlabel(1 "2010/11" 2 "2012/13" 3 "2014/15" 4 "2016/17" 5 "2018/19" 6 "2020/21", alternate) xtitle("") xscale(range(0.9 6.1))

graph save sweden.gph, replace

graph combine germany.gph sweden.gph, graphregion(color(white))
graph export "Figure2.pdf", replace

********************************************************************************************************************************************************************************************************
***********************************************************************DATASET PREPARATION FOR FIGURES 3, 4 AND 5***************************************************************************************
********************************************************************************************************************************************************************************************************
***Germany
use "Exp_Ger.dta", clear

*generate variable for treatment group
gen group=.
replace group=1 if splitgroup==2
replace group=2 if splitgroup==3
replace group=3 if splitgroup==1
lab def splitgroup 1 "Deleg" 2 "No cue" 3 "Leg" 
lab val group splitgroup

*Recode "Don't Know" to missing 
foreach var in q12_*{
   recode `var' (977=.)
 }

 *Reverse scales if necessary 
revrs q12_5 q12_7 q12_8  
drop q12_5 q12_7 q12_8  
rename revq12_5 q12_5
rename revq12_7 q12_7
rename revq12_8 q12_8
*Rescale to 0-1-scale
nscale q12_*

drop q12_1 q12_2 q12_3 q12_4 q12_5 q12_6 q12_7 q12_8 q12_9

foreach var in q12_*_01{
   rename `var' q12_*
 }
 
gen country="Germany"
 
*generate indeces/DVs
alpha q12_8 q12_9
egen percepindex = rowmean (q12_8 q12_9)

alpha q12_2 q12_3 q12_4 q12_5
egen tolindex = rowmean (q12_2 q12_3 q12_4 q12_5)  

keep country group percepindex tolindex q12_1 q8 manipulation1 manipulation2 q13_6 q14_6
save germany.dta, replace

***Sweden
use "Exp_Swe.dta", clear

*The outcome measures for the control group were stored in a different variable by YouGov.
replace q5_1=q6_1 if Group_split==1
replace q5_2=q6_2 if Group_split==1
replace q5_3=q6_3 if Group_split==1
replace q5_4=q6_4 if Group_split==1
replace q5_5=q6_5 if Group_split==1
replace q5_6=q6_6 if Group_split==1
replace q5_7=q6_7 if Group_split==1
replace q5_8=q6_8 if Group_split==1
replace q5_9=q6_9 if Group_split==1
replace q5_10=q6_10 if Group_split==1
replace q5_11=q6_11 if Group_split==1
replace q5_12=q6_12 if Group_split==1
replace q5_13=q6_13 if Group_split==1

*generate variable for treatment group
gen group=.
replace group=1 if Group_split==2
replace group=2 if Group_split==1
replace group=3 if Group_split==3
replace group=4 if Group_split==4
lab def splitgroup 1 "Deleg" 2 "No cue" 3 "Leg" 4 "M Leg & C Deleg"
lab val group splitgroup

*Recode "Don't Know" to missing 
foreach var in q5_*{
   recode `var' (977=.)
 }
*Reverse scales if necessary 
revrs q5_1 q5_3 q5_5 q5_8 
drop q5_1 q5_1 q5_3 q5_5 q5_8
rename revq5_1 q5_1
rename revq5_3 q5_3
rename revq5_5 q5_5
rename revq5_8 q5_8
*Rescale to 0-1-scale
nscale q5_*
drop q5_1 q5_2 q5_3 q5_4 q5_5 q5_6 q5_7 q5_8 q5_9 q5_10 q5_11 q5_12 q5_13

foreach var in q5_*_01{
   rename `var' q5_*
 }

gen country="Sweden"
replace q3=9 if country=="Sweden" & q3==.
 
*generate indeces
alpha q5_3 q5_4
egen percepindex = rowmean (q5_3 q5_4)

alpha q5_5 q5_6 q5_7 q5_8
egen tolindex = rowmean (q5_5 q5_6 q5_7 q5_8)  
 
save sweden.dta, replace 

*** merge the two datasets
keep country group percepindex tolindex q5_1 q3 q12 q13 q14 q15 q7_8 q8_8
append using germany.dta


********************************************************************************************************************************************************************************************************
*********************************************************************************FIGURE 3**************************************************************************************************************
********************************************************************************************************************************************************************************************************
reg percepindex b1.group if country=="Germany" // NOTE: FOR STYLISTIC REASONS COEFFICIENTS, BRACES, AND INDICATORS OF SIGNIFICANCE WERE ADDED LATER TO THE FIGURES
margins group, saving(germany, replace)
reg percepindex b1.group i.q3 if country=="Sweden" & group!=4
margins group, saving(sweden, replace)
combomarginsplot germany sweden, scheme(s1mono) title ("    Legitimacy") recast(scatter) recastci(rspike) ylabel(0(.2)1) plotopts(mlabel(_margin) mlabformat(%12.2f) mlabgap(2)) xtitle("") xscale(r(0.9 3.1)) labels("Germany (CDU)" "Sweden (M)") ytitle("") graphregion(margin(l-5)) plot2opts(mlabc(gs10) mlabp(12)) plot1opts(mlabc(gs0) mc(gs0) mlabp(6)) ci1opts (lc(black)) saving (legitimacy, replace)

reg tolindex b1.group if country=="Germany"
outreg2 using manipswe, replace dec(2) adjr word
margins group, saving(germany, replace)
reg tolindex b1.group i.q3  if country=="Sweden" & group!=4
margins group, saving(sweden, replace)
combomarginsplot germany sweden, scheme(s1mono)  title ("Tolerance") recast(scatter) recastci(rspike) ylabel(0(.2)1) plotopts(mlabel(_margin) mlabformat(%12.2f) mlabgap(2)) xtitle("")  xscale(r(0.9 3.1))  labels("Germany (CDU)" "Sweden (M)") yscale(off) plot2opts(mlabc(gs10) mlabp(12)) plot1opts(mlabc(gs0) mc(gs0) mlabp(6)) ci1opts (lc(black)) saving (tolerance, replace)

reg q12_1 b1.group if country=="Germany"
margins group
marginsplot, scheme(s1mono) title ("Against Boycott") recast(scatter) recastci(rspike) ylabel(0(.2)1) plotopts(mlabel(_margin) mlabformat(%12.2f) mlabp(6) mlabgap(2)) xtitle("") yscale(off) xscale(r(0.9 3.1)) plot1opts(mlabc(gs0) mc(gs0)) ci1opts (lc(black)) saving (boycott, replace)

reg q5_1 b1.group i.q3  if country=="Sweden" & group!=4
margins group
marginsplot, scheme(s1mono) title ("Ministers") recast(scatter) recastci(rspike) ylabel(0(.2)1) plotopts(mlabel(_margin) mlabp(12) mlabformat(%12.2f) mlabgap(2) msymbol(D) mcolor(gs10)) ci1opt(color(gs10)) xtitle("") xscale(r(0.9 3.1)) yscale(off) plot1opts(mlabc(gs10) mc(gs10)) ciopts(lc(gs10)) saving (ministers, replace) 

grc1leg legitimacy.gph tolerance.gph boycott.gph ministers.gph, cols(4) l1(Evaluations of AfD & SD (Scale 0-1)) b1(Experimental condition) graphregion(color(white)) ring(2) // NOTE: FOR STYLISTIC REASONS COEFFICIENTS, BRACES, AND INDICATORS OF SIGNIFICANCE WERE ADDED LATER TO THE FIGURES
graph export "Figure3.pdf", replace 

********************************************************************************************************************************************************************************************************
*********************************************************************************FIGURE 4**************************************************************************************************************
********************************************************************************************************************************************************************************************************
reg percepindex i.group i.q3 if country=="Sweden" & group>2
margins i.group
marginsplot, scheme(s1mono) title ("    Legitimacy") recast(scatter) recastci(rspike) ylabel(0(.2)1) plotopts(mlabel(_margin) mlabp(12) msymbol(D)  mlabformat(%12.2f) mlabgap(3) mlabc(gs10)  mcolor(gs10)) ci1opt(color(gs10)) xtitle("") ytitle("") xscale(r(2.8 4.3))  graphregion(margin(l-5)) saving(legitimacy, replace)

reg tolindex i.group i.q3 if country=="Sweden" & group>2
margins i.group
marginsplot, scheme(s1mono) title ("Tolerance") recast(scatter) recastci(rspike) ylabel(0(.2)1) plotopts(mlabel(_margin) mlabp(12) msymbol(D)   mlabformat(%12.2f) mlabgap(3) mlabc(gs10)  mcolor(gs10)) ci1opt(color(gs10)) xtitle("") yscale(off) xscale(r(2.8 4.3)) saving (tolerace, replace)

reg q5_1 i.group i.q3 if country=="Sweden" & group>2
margins i.group
marginsplot, scheme(s1mono) title ("Ministers") recast(scatter) recastci(rspike) ylabel(0(.2)1) plotopts(mlabel(_margin) mlabp(12) msymbol(D)  mlabgap(3) mlabformat(%12.2f) mlabc(gs10)  mcolor(gs10)) ci1opt(color(gs10)) xtitle("") yscale(off) xscale(r(2.8 4.3)) saving (ministers, replace) 

graph combine legitimacy.gph tolerace.gph ministers.gph, rows(1) l1(Evaluation of SD (Scale 0-1)) graphregion(color(white)) b1(Experimental condition)  // NOTE: FOR STYLISTIC REASONS COEFFICIENTS, BRACES, AND INDICATORS OF SIGNIFICANCE WERE ADDED LATER TO THE FIGURES
graph export "Figure4.pdf", replace


********************************************************************************************************************************************************************************************************
*********************************************************************************FIGURE 5**************************************************************************************************************
********************************************************************************************************************************************************************************************************
reg percepindex b1.group if q8==1 & country=="Germany"
margins group, saving(cdu, replace)
reg percepindex b1.group if q8!=1 & q8!=6 & country=="Germany"
margins group, saving(others, replace)
reg percepindex b1.group if q8==6 & country=="Germany"
margins group, saving(afd, replace)
combomarginsplot cdu others afd, scheme(s1mono) title ("Legitimacy") recast(scatter) recastci(rspike) ylabel(0(.2)1) plotopts(mlabel(_margin) mlabformat(%12.2f)mcolor(gs0)) xtitle("") labels("CDU supporters" "Others" "AfD supporters") ciopt(color(gs0)) xscale(r(0.7 3.3)) ytitle("") legend (cols(3)) plot1opts(msymbol(S) mlabp(9)) plot2opts(msymbol(Oh) mlabp(3)) plot3opts(msymbol(X) mlabp(3)) saving (germanyleg, replace)

reg tolindex b2.group if q8==1 & country=="Germany"
margins group, saving(cdu, replace)
reg tolindex b2.group if q8!=1 & q8!=6 & country=="Germany"
margins group, saving(others, replace)
reg tolindex b2.group if q8==6 & country=="Germany"
margins group, saving(afd, replace)
combomarginsplot cdu others afd, scheme(s1mono) title ("Tolerance") recast(scatter) recastci(rspike) ylabel(0(.2)1) plotopts(mlabel(_margin) mlabformat(%12.2f)mcolor(gs0)) xtitle("") labels("CDU supporters" "Others" "AfD supporters") ciopt(color(gs0)) xscale(r(0.7 3.4)) ytitle("") legend (cols(3)) plot1opts(msymbol(S) mlabp(9)) plot2opts(msymbol(Oh) mlabp(3)) plot3opts(msymbol(X) mlabp(3)) yscale(off) saving (germanytol, replace)

reg q12_1 b2.group if q8==1 & country=="Germany"
margins group, saving(cdu, replace)
reg q12_1 b2.group if q8!=1 & q8!=6 & country=="Germany"
margins group, saving(others, replace)
reg q12_1 b2.group if q8==6 & country=="Germany"
margins group, saving(afd, replace)
combomarginsplot cdu others afd, scheme(s1mono) title ("Against boycott") recast(scatter) recastci(rspike) ylabel(0(.2)1) plotopts(mlabel(_margin) mlabformat(%12.2f) mcolor(gs0)) xtitle("") labels("CDU supporters" "Others" "AfD supporters") ciopt(color(gs0)) xscale(r(0.7 3.4)) ytitle("") legend (cols(3)) plot1opts(msymbol(S) mlabp(9)) plot2opts(msymbol(Oh) mlabp(3)) plot3opts(msymbol(X) mlabp(3)) yscale(off) saving (germanyab, replace)
grc1leg2 germanyleg.gph germanytol.gph germanyab.gph, l1(Evaluations of AfD (Scale 0-1)) r1(Germany, orientation(rvertical)) graphregion(color(white)) cols(3) saving (germany, replace)

reg percepindex b2.group if q3==1 & country=="Sweden" & group!=4
margins group, saving(m, replace)
reg percepindex b2.group if q3!=1 & q3!=8 & country=="Sweden" & group!=4
margins group, saving(others, replace)
reg percepindex b2.group if q3==8 & country=="Sweden" & group!=4
margins group, saving(sd, replace)
combomarginsplot m others sd, scheme(s1mono) title ("Legitimacy") recast(scatter) recastci(rspike) ylabel(0(.2)1) plotopts(mlabel(_margin) mlabp(3) mlabformat(%12.2f) mlabc(gs10) mcolor(gs10)) xtitle("") labels("M supporters" "Others" "SD supporters") ciopts(color(gs10)) xscale(r(0.9 3.4)) ytitle("") legend (cols(3)) plot1opts(msymbol(S)) plot2opts(msymbol(Oh)) plot3opts(msymbol(X)) saving (swedenleg, replace)

reg tolindex b2.group if q3==1 & country=="Sweden" & group!=4
margins group, saving(m, replace)
reg tolindex b2.group if q3!=1 & q3!=8 & country=="Sweden" & group!=4
margins group, saving(others, replace)
reg tolindex b2.group if q3==8 & country=="Sweden" & group!=4
margins group, saving(sd, replace)
combomarginsplot m others sd, scheme(s1mono) title ("Tolerance") recast(scatter) recastci(rspike) ylabel(0(.2)1) plotopts(mlabel(_margin) mlabp(3) mlabformat(%12.2f) mlabc(gs10) mcolor(gs10)) xtitle("") labels("M supporters" "Others" "SD supporters") ciopts(color(gs10)) xscale(r(0.9 3.4)) yscale(off) legend (cols(3)) plot1opts(msymbol(S) ) plot2opts(msymbol(Oh)) plot3opts(msymbol(X)) saving (swedentol, replace)

reg q5_1 b2.group if q3==1 & country=="Sweden" & group!=4
margins group, saving(m, replace)
reg q5_1 b2.group if q3!=1 & q3!=8 & country=="Sweden" & group!=4
margins group, saving(others, replace)
reg q5_1 b2.group if q3==8 & country=="Sweden" & group!=4
margins group, saving(sd, replace)
combomarginsplot m others sd, scheme(s1mono) title ("Ministers") recast(scatter) recastci(rspike) ylabel(0(.2)1) plotopts(mlabel(_margin) mlabp(3) mlabformat(%12.2f) mlabc(gs10) mcolor(gs10)) xtitle("") labels("M supporters" "Others" "SD supporters") ciopts(color(gs10)) xscale(r(0.9 3.4)) yscale(off) legend (cols(3)) plot1opts(msymbol(S)) plot2opts(msymbol(Oh)) plot3opts(msymbol(X)) saving (swedenab, replace)

grc1leg2 swedenleg.gph swedentol.gph swedenab.gph, l1(Evaluations of SD (Scale 0-1)) r1(Sweden, orientation(rvertical)) graphregion(color(white)) cols(3) saving (sweden, replace)

graph combine germany.gph sweden.gph, rows(2) b1(Experimental condition) graphregion(color(white))
graph export "Figure5.pdf", replace

********************************************************************************************************************************************************************************************************
*********************************************************************************APPENDIX**************************************************************************************************************
********************************************************************************************************************************************************************************************************

*** Manipulation check:Table SI6 (Germany)
recode manipulation1 (977=.)
revrs manipulation1
reg revmanipulation1 i.group
outreg2 using manipger, replace dec(2) adjr word
*** Manipulation check:Table SI6 (Germany)
recode manipulation2 (977=.)
revrs manipulation2
reg revmanipulation2 i.group
outreg2 using manipger, append dec(2) adjr word

*** Manipulation check:Table SI7 (Sweden)
recode q12(977=.)
revrs q12
reg revq12 i.group if country=="Sweden" 
outreg2 using manipswe, replace dec(2) adjr word
*** Manipulation check:Table SI7 (Sweden)
recode q14(977=.)
revrs q14
reg revq14 i.group 
outreg2 using manipswe, append dec(2) adjr word
*** Manipulation check:Table SI8 (Sweden)
revrs q13
revrs q15
sum revq12 revq13 revq14 revq15 if group==4

***Table SI9/Figure 3 (only Germany)
reg percepindex i.group if country=="Germany" & group!=2
outreg2 using fig3ger, replace dec(2) adjr word
reg tolindex i.group if country=="Germany" & group!=2
outreg2 using fig3ger, append dec(2) adjr word
reg q12_1 i.group if country=="Germany" & group!=2
outreg2 using fig3ger, append dec(2) adjr word
reg percepindex b2.group if country=="Germany"
outreg2 using fig3ger, append dec(2) adjr word
reg tolindex b2.group if country=="Germany"
outreg2 using fig3ger, append dec(2) adjr word
reg q12_1 b2.group if country=="Germany"
outreg2 using fig3ger, append dec(2) adjr word

***Table SI10/Figure 3 (only Sweden)
reg percepindex i.group i.q3 if country=="Sweden" & group!=2 & group!=4
outreg2 using fig3swe, replace dec(2) adjr word 
reg tolindex i.group i.q3 if country=="Sweden" & group!=2 & group!=4
outreg2 using fig3swe, append dec(2) adjr word
reg q5_1 i.group i.q3 if country=="Sweden" & group!=2 & group!=4
outreg2 using fig3ger, append dec(2) adjr word
reg percepindex b2.group i.q3 if country=="Sweden" & group!=4
outreg2 using fig3swe, append dec(2) adjr word
reg tolindex b2.group i.q3 if country=="Sweden" & group!=4
outreg2 using fig3swer, append dec(2) adjr word
reg q5_1 b2.group i.q3 if country=="Sweden" & group!=4
outreg2 using fig3swe, append dec(2) adjr word

***Table SI11/Figure 4 (only Sweden)
reg percepindex i.group i.q3 if country=="Sweden" & group>2
outreg2 using fig4, replace dec(2) adjr word 
reg tolindex i.group i.q3 if country=="Sweden" & group>2
outreg2 using fig4, append dec(2) adjr word
reg q5_1 i.group i.q3 if country=="Sweden" & group>2
outreg2 using fig4, append dec(2) adjr word

***Table SI12/Figure 5 (only Germany)
reg percepindex i.group if group!=2 & q8==1 & country=="Germany"
outreg2 using fig5ger, replace addtext(Partisanship,CDU) dec(2) adjr word
reg tolindex i.group if group!=2 & q8==1 & country=="Germany"
outreg2 using fig5ger, append addtext(Partisanship,CDU) dec(2) adjr word
reg q12_1 i.group if group!=2 & q8==1 & country=="Germany"
outreg2 using fig5ger, append addtext(Partisanship,CDU) dec(2) adjr word
reg percepindex b2.group if q8==1 & country=="Germany"
outreg2 using fig5ger, append addtext(Partisanship,CDU) dec(2) adjr word 
reg tolindex b2.group if q8==1 & country=="Germany"
outreg2 using fig5ger, append addtext(Partisanship,CDU) dec(2) adjr word
reg q12_1 b2.group if q8==1 & country=="Germany"
outreg2 using fig5ger, append addtext(Partisanship,CDU) dec(2) adjr word

reg percepindex i.group if group!=2 & q8!=1 & q8!=6 & country=="Germany"
outreg2 using fig5ger, append addtext(Partisanship,Others) dec(2) adjr word
reg tolindex i.group if group!=2 & q8!=1 & q8!=6 & country=="Germany"
outreg2 using fig5ger, append addtext(Partisanship,Others) dec(2) adjr word
reg q12_1 i.group if group!=2 & q8!=1 & q8!=6 & country=="Germany"
outreg2 using fig5ger, append addtext(Partisanship,Others) dec(2) adjr word
reg percepindex b2.group if q8!=1 & q8!=6 & country=="Germany"
outreg2 using fig5ger, append addtext(Partisanship,Others) dec(2) adjr word 
reg tolindex b2.group if q8!=1 & q8!=6 & country=="Germany"
outreg2 using fig5ger, append addtext(Partisanship,Others) dec(2) adjr word
reg q12_1 b2.group if q8!=1 & q8!=6 & country=="Germany"
outreg2 using fig5ger, append addtext(Partisanship,Others) dec(2) adjr word


reg percepindex i.group if group!=2 & q8==6 & country=="Germany"
outreg2 using fig5ger, append addtext(Partisanship,AfD) dec(2) adjr word
reg tolindex i.group if group!=2 & q8==6 & country=="Germany"6
outreg2 using fig5ger, append addtext(Partisanship,AfD) dec(2) adjr word
reg q12_1 i.group if group!=2 & q8==6 & country=="Germany"
outreg2 using fig5ger, append addtext(Partisanship,AfD) dec(2) adjr word
reg percepindex b2.group if q8==6 & country=="Germany"
outreg2 using fig5ger, append addtext(Partisanship,AfD) dec(2) adjr word
reg tolindex b2.group if q8==6 & country=="Germany"6
outreg2 using fig5ger, append addtext(Partisanship,AfD) dec(2) adjr word
reg q12_1 b2.group if q8==6 & country=="Germany"
outreg2 using fig5ger, append addtext(Partisanship,AfD) dec(2) adjr word

***Table SI13/Figure 5 (only Sweden)
reg percepindex i.group if group!=2 & group!=4 & q3==1 & country=="Sweden"
outreg2 using fig5swe, replace addtext(Partisanship,M) dec(2) adjr word
reg tolindex i.group if group!=2 & group!=4 & q3==1 & country=="Sweden"
outreg2 using fig5swe, append addtext(Partisanship,M) dec(2) adjr word
reg q5_1 i.group if group!=2 & group!=4 & q3==1 & country=="Sweden"
outreg2 using fig5swe, append addtext(Partisanship,M) dec(2) adjr word
reg percepindex b2.group if q3==1 & country=="Sweden" & group!=4
outreg2 using fig5ger, append addtext(Partisanship,M) dec(2) adjr word 
reg tolindex b2.group if q3==1 & country=="Sweden" & group!=4
outreg2 using fig5swe, append addtext(Partisanship,M) dec(2) adjr word
reg q5_1 b2.group if q3==1 & country=="Sweden" & group!=4
outreg2 using fig5swe, append addtext(Partisanship,M) dec(2) adjr word

reg percepindex i.group if group!=2 & q3!=1 & q3!=8 & country=="Sweden" & group!=4
outreg2 using fig5swe, append addtext(Partisanship,Others) dec(2) adjr word
reg tolindex i.group if group!=2 & q3!=1 & q3!=8 & country=="Sweden" & group!=4
outreg2 using fig5swe, append addtext(Partisanship,Others) dec(2) adjr word
reg q5_1 i.group if group!=2 & q3!=1 & q3!=8 & country=="Sweden" & group!=4
outreg2 using fig5swe, append addtext(Partisanship,Others) dec(2) adjr word
reg percepindex b2.group if q3!=1 & q3!=8 & country=="Sweden" & group!=4
outreg2 using fig5swe, append addtext(Partisanship,Others) dec(2) adjr word 
reg tolindex b2.group if q3!=1 & q3!=8 & country=="Sweden" & group!=4
outreg2 using fig5swe, append addtext(Partisanship,Others) dec(2) adjr word
reg q5_1 b2.group if q3!=1 & q3!=8 & country=="Sweden" & group!=4
outreg2 using fig5swe, append addtext(Partisanship,Others) dec(2) adjr word

reg percepindex i.group if group!=2 & q3==8 & country=="Sweden" & group!=4
outreg2 using fig5swe, append addtext(Partisanship,SD) dec(2) adjr word
reg tolindex i.group if group!=2 & q3==8 & country=="Sweden"6 & group!=4
outreg2 using fig5swe, append addtext(Partisanship,SD) dec(2) adjr word
reg q5_1 i.group if group!=2 & q3==8 & country=="Sweden" & group!=4
outreg2 using fig5swe, append addtext(Partisanship,SD) dec(2) adjr word
reg percepindex b2.group if q3==8 & country=="Sweden" & group!=4
outreg2 using fig5swe, append addtext(Partisanship,SD) dec(2) adjr word
reg tolindex b2.group if q3==8 & country=="Sweden" & group!=4
outreg2 using fig5swe, append addtext(Partisanship,SD) dec(2) adjr word
reg q5_1 b2.group if q3==8 & country=="Sweden" & group!=4
outreg2 using fig5swe, append addtext(Partisanship,SD) dec(2) adjr word

***Table SI14 (only Sweden)
reg percepindex i.group if country=="Sweden" & group!=2 & group!=4
outreg2 using fig3, replace dec(2) adjr word 
reg tolindex i.group if country=="Sweden" & group!=2 & group!=4
outreg2 using fig3, append dec(2) adjr word
reg q5_1 i.group if country=="Sweden" & group!=2 & group!=4
outreg2 using fig3, append dec(2) adjr word
reg percepindex b2.group i.q3 if country=="Sweden" & group!=4
outreg2 using fig3, append dec(2) adjr word
reg tolindex b2.group if country=="Sweden" & group!=4
outreg2 using fig3, append dec(2) adjr word
reg q5_1 b2.group if country=="Sweden" & group!=4
outreg2 using fig3, append dec(2) adjr word

***Table SI15 (only Sweden)
reg percepindex i.group if country=="Sweden" & group>2
outreg2 using fig4, replace dec(2) adjr word 
reg tolindex i.group if country=="Sweden" & group>2
outreg2 using fig4, append dec(2) adjr word
reg q5_1 i.group if country=="Sweden" & group>2
outreg2 using fig4, append dec(2) adjr word

***Table SI16 
*PTV for AfD
recode q13_6 (977=.)
nscale q13_6
reg q13_6_01 i.group
outreg2 using ptvger, replace dec(2) adjr word
reg q13_6_01 b2.group if group!=0
outreg2 using ptvger, append dec(2) adjr word
* Anger towards AfD
recode q14_6 (977=.)
nscale q14_6
reg q14_6_01 i.group
outreg2 using ptvger, append dec(2) adjr word
reg q14_6_01 b2.group if group!=0
outreg2 using ptvger, append dec(2) adjr word

***Table SI17
recode q7_8 (977=.)
recode q8_8 (977=.)
nscale q7_8
nscale q8_8
reg q7_8_01 i.group i.q3 if group!=4 & group!=2
outreg2 using ptvswe1, replace dec(2) adjr word
reg q8_8_01 i.group i.q3 if group!=4 & group!=2
outreg2 using ptvswe1, append dec(2) adjr word
reg q7_8_01 i.group i.q3 if group!=4
outreg2 using ptvswe1, append dec(2) adjr word
reg q8_8_01 i.group i.q3 if group!=4
outreg2 using ptvswe1, append dec(2) adjr word

***Table SI17
reg q7_8_01 i.group if group!=4 & group!=2
outreg2 using ptvswe2, replace dec(2) adjr word
reg q8_8_01 i.group if group!=4 & group!=2
outreg2 using ptvswe2, append dec(2) adjr word
reg q7_8_01 i.group if group!=4
outreg2 using ptvswe2, append dec(2) adjr word
reg q8_8_01 i.group if group!=4
outreg2 using ptvswe2, append dec(2) adjr word

***Table SI21
gen cdu=0
replace cdu=1 if q8==1
reg percepindex i.group##cdu if group!=2 & country=="Germany"
outreg2 using intercdu, replace dec(2) adjr word
gen m=0
replace m=1 if q3==1
reg percepindex i.group##m if group!=2 & country=="Sweden" & group!=4
outreg2 using intercdu, append dec(2) adjr word

***Table SI22
gen bloc=.
replace bloc=1 if q3==1 | q3==3 | q3==4
replace bloc=0 if  q3==2 | q3==5 | q3==6 | q3==7
reg percepindex i.group if group!=4 & group!=1 & bloc==1
outreg2 using bloc, replace dec(2) adjr word

reg percep i.group if group!=4 & group!=1 & bloc==0
outreg2 using bloc, append dec(2) adjr word
reg percep i.group##bloc if group!=4 & group!=1
outreg2 using bloc, append dec(2) adjr word
